//
//  ZMDiscoverInsetHeadViewCell.m
//  基本框架
//
//  Created by runone02 on 2018/7/4.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

#import "ZMDiscoverInsetHeadViewCell.h"
#import "ZMDiscoverHeadModel.h"

@interface ZMDiscoverInsetHeadViewCell()<SPPageMenuDelegate>

@end

@implementation ZMDiscoverInsetHeadViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
    }
    return self;
}

- (void) setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    if (!_pageMenu) {
        _pageMenu = [SPPageMenu pageMenuWithFrame:CGRectMake(0, 0, self.width, self.height) trackerStyle:SPPageMenuTrackerStyleLineAttachment];
        _pageMenu.permutationWay = SPPageMenuPermutationWayScrollAdaptContent;
        _pageMenu.itemPadding = 45;
        _pageMenu.closeTrackerFollowingMode = YES;
        _pageMenu.hideLine = YES;
        _pageMenu.unSelectedItemTitleColor = [ZMColor appSupportColor];
        
        //传递数组默认选中第一个
        NSMutableArray *itemArray = [[NSMutableArray alloc]init];
        for (id model in dataArray) {
            if ([model isKindOfClass:[ZMDiscoverHeadModel class]]) {
                [itemArray addObject:((ZMDiscoverHeadModel*)model).title];
            }
        }
        
        [_pageMenu setItems:itemArray selectedItemIndex:0];
        
        for (int i = 0; i < dataArray.count; i++) {
            id model = [dataArray safeObjectAtIndex:i];
            if ([model isKindOfClass:[ZMDiscoverHeadModel class]]) {
                ZMDiscoverHeadModel *headModel = model;
                [_pageMenu setTitle:headModel.title image:IMAGE(headModel.img) imagePosition:SPItemImagePositionTop imageRatio:0.5 forItemIndex:i];
            }
        }
        _pageMenu.showFuntionButton = NO;
        _pageMenu.delegate =self;
        [self.contentView addSubview:_pageMenu];
    }
}

- (void)pageMenu:(SPPageMenu *)pageMenu itemSelectedAtIndex:(NSInteger)index{
    NSLog(@"顶顶顶大雕%ld",index);
}


@end
